<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java并发编程：Future与CompletableFuture深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
            background-color: #f9f9f9;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #2d3748;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #282c34;
            border-radius: 8px;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .feature-card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .comparison-table {
            border-collapse: separate;
            border-spacing: 0;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .comparison-table th {
            background-color: #4a5568;
            color: white;
        }
        .comparison-table tr:nth-child(even) td {
            background-color: #f7fafc;
        }
        .comparison-table tr:hover td {
            background-color: #ebf8ff;
        }
        .footer {
            background-color: #2d3748;
        }
        .footer a:hover {
            color: #a0aec0;
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: "";
            position: absolute;
            bottom: 0.1em;
            left: 0;
            width: 100%;
            height: 0.4em;
            background-color: rgba(118, 75, 162, 0.2);
            z-index: -1;
            border-radius: 2px;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6">Java并发编程：Future与CompletableFuture<span class="highlight">深度解析</span></h1>
                    <p class="text-xl md:text-2xl opacity-90 mb-8">探索异步编程的强大工具，构建高性能Java应用</p>
                    <div class="flex items-center space-x-4">
                        <div class="flex items-center">
                            <i class="fas fa-clock text-yellow-300 mr-2"></i>
                            <span>阅读时间: 8分钟</span>
                        </div>
                        <div class="flex items-center">
                            <i class="fas fa-layer-group text-green-300 mr-2"></i>
                            <span>进阶内容</span>
                        </div>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative w-64 h-64">
                        <div class="absolute inset-0 bg-purple-500 rounded-full opacity-20" style="transform: translateX(-10px) translateY(-10px)"></div>
                        <div class="absolute inset-0 bg-blue-500 rounded-full opacity-20" style="transform: translateX(10px) translateY(10px)"></div>
                        <div class="relative z-10 flex items-center justify-center h-full">
                            <i class="fas fa-bolt text-6xl text-yellow-300 animate-pulse"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-xl p-8 shadow-lg">
                <p class="text-lg leading-relaxed mb-6">在Java并发编程中，<span class="font-bold text-purple-700">Future</span>和<span class="font-bold text-blue-600">CompletableFuture</span>是两个非常重要的工具类。它们都用于处理异步任务，即在执行某个任务时，主线程可以不阻塞等待结果，从而提高程序的性能和响应性。然而，它们的使用场景和功能差异却很大。</p>
                <div class="flex flex-wrap justify-center gap-4">
                    <div class="px-4 py-2 bg-purple-100 text-purple-800 rounded-full flex items-center">
                        <i class="fas fa-clock mr-2"></i>
                        <span>JDK 5引入</span>
                    </div>
                    <div class="px-4 py-2 bg-blue-100 text-blue-800 rounded-full flex items-center">
                        <i class="fas fa-bolt mr-2"></i>
                        <span>JDK 8引入</span>
                    </div>
                    <div class="px-4 py-2 bg-indigo-100 text-indigo-800 rounded-full flex items-center">
                        <i class="fas fa-project-diagram mr-2"></i>
                        <span>并发编程</span>
                    </div>
                </div>
            </div>
        </section>

        <!-- Future Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="w-8 h-8 bg-purple-600 rounded-full flex items-center justify-center text-white mr-4">1</span>
                什么是Future？
            </h2>
            <div class="bg-white rounded-xl p-8 shadow-lg mb-8">
                <p class="mb-6"><span class="font-bold text-purple-700">Future</span>是Java中提供的一种用于异步任务执行的接口。通过<span class="font-bold">Future</span>，我们可以在后台线程中执行一个耗时的操作，而主线程不需要等待该操作完成，可以继续执行其他任务。<span class="font-bold">Future</span>提供了一些方法来检查任务的执行状态和获取任务结果。</p>
                
                <h3 class="text-2xl font-semibold mt-8 mb-4 flex items-center">
                    <i class="fas fa-list-ul text-purple-600 mr-3"></i>
                    Future的主要方法
                </h3>
                <div class="grid md:grid-cols-2 gap-6 mb-8">
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 mr-4">
                                <i class="fas fa-download"></i>
                            </div>
                            <h4 class="font-bold text-lg">get()</h4>
                        </div>
                        <p class="text-gray-700">用于获取异步任务的执行结果。如果任务尚未完成，调用get()方法会阻塞当前线程，直到任务完成并返回结果。</p>
                    </div>
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 mr-4">
                                <i class="fas fa-check-circle"></i>
                            </div>
                            <h4 class="font-bold text-lg">isDone()</h4>
                        </div>
                        <p class="text-gray-700">用于检查任务是否已经完成，返回true表示任务已经完成，无论是正常完成还是异常完成。</p>
                    </div>
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 mr-4">
                                <i class="fas fa-ban"></i>
                            </div>
                            <h4 class="font-bold text-lg">cancel()</h4>
                        </div>
                        <p class="text-gray-700">用于取消任务。如果任务尚未开始执行，调用cancel()方法会使任务被取消；如果任务已经开始执行，则无法取消。</p>
                    </div>
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 mr-4">
                                <i class="fas fa-times-circle"></i>
                            </div>
                            <h4 class="font-bold text-lg">isCancelled()</h4>
                        </div>
                        <p class="text-gray-700">用于检查任务是否已被取消。</p>
                    </div>
                </div>

                <div class="mb-8">
                    <h3 class="text-xl font-semibold mb-4 flex items-center text-purple-700">
                        <i class="fas fa-code mr-2"></i>
                        示例代码
                    </h3>
                    <div class="code-block p-4 rounded-lg text-gray-200 overflow-x-auto">
                        <pre><code class="language-java">import java.util.concurrent.*;

public class FutureDemo {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        Callable&lt;Integer&gt; task = () -> {
            Thread.sleep(2000); // 模拟耗时操作
            return 42;
        };

        Future&lt;Integer&gt; future = executorService.submit(task);
        System.out.println("主线程继续执行...");
        System.out.println("任务结果: " + future.get()); // 会阻塞，直到任务完成
        executorService.shutdown();
    }
}</code></pre>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 flex items-center">
                    <i class="fas fa-exclamation-triangle text-yellow-500 mr-3"></i>
                    Future的不足
                </h3>
                <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-exclamation-circle text-yellow-400 mt-1 mr-3"></i>
                        </div>
                        <div>
                            <p class="font-medium text-yellow-800">阻塞调用</p>
                            <p class="text-yellow-700">get()方法是阻塞的，意味着主线程会在调用get()时等待异步任务完成，直到任务完成后才能继续执行后续操作。</p>
                        </div>
                    </div>
                </div>
                <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-exclamation-circle text-yellow-400 mt-1 mr-3"></i>
                        </div>
                        <div>
                            <p class="font-medium text-yellow-800">缺少处理回调</p>
                            <p class="text-yellow-700">Future本身不提供处理任务完成后的回调机制，需要通过轮询的方式判断任务是否完成，这样会降低效率。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- CompletableFuture Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="w-8 h-8 bg-blue-600 rounded-full flex items-center justify-center text-white mr-4">2</span>
                什么是CompletableFuture？
            </h2>
            <div class="bg-white rounded-xl p-8 shadow-lg mb-8">
                <p class="mb-6"><span class="font-bold text-blue-600">CompletableFuture</span>是Java 8引入的一个类，扩展了<span class="font-bold">Future</span>接口，提供了更强大的异步编程支持。它不仅能处理异步任务，还支持任务完成后的回调处理（如成功、失败等）。与<span class="font-bold">Future</span>相比，<span class="font-bold">CompletableFuture</span>更灵活，支持链式操作、多个任务的组合、异常处理等高级功能。</p>
                
                <h3 class="text-2xl font-semibold mt-8 mb-4 flex items-center">
                    <i class="fas fa-list-ul text-blue-600 mr-3"></i>
                    CompletableFuture的主要方法
                </h3>
                <div class="grid md:grid-cols-2 gap-6 mb-8">
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center text-blue-600 mr-4">
                                <i class="fas fa-bolt"></i>
                            </div>
                            <h4 class="font-bold text-lg">supplyAsync()</h4>
                        </div>
                        <p class="text-gray-700">用于异步执行一个任务，并返回结果。</p>
                    </div>
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center text-blue-600 mr-4">
                                <i class="fas fa-arrow-right"></i>
                            </div>
                            <h4 class="font-bold text-lg">thenApply()</h4>
                        </div>
                        <p class="text-gray-700">用于在任务完成后执行某个操作，并返回一个新的结果。</p>
                    </div>
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center text-blue-600 mr-4">
                                <i class="fas fa-check"></i>
                            </div>
                            <h4 class="font-bold text-lg">thenAccept()</h4>
                        </div>
                        <p class="text-gray-700">用于在任务完成后执行某个操作，但不返回结果。</p>
                    </div>
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center text-blue-600 mr-4">
                                <i class="fas fa-bug"></i>
                            </div>
                            <h4 class="font-bold text-lg">exceptionally()</h4>
                        </div>
                        <p class="text-gray-700">用于处理异步任务执行中的异常。</p>
                    </div>
                    <div class="feature-card bg-white p-6 rounded-lg border border-gray-200">
                        <div class="flex items-center mb-3">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center text-blue-600 mr-4">
                                <i class="fas fa-link"></i>
                            </div>
                            <h4 class="font-bold text-lg">thenCombine()</h4>
                        </div>
                        <p class="text-gray-700">用于合并两个异步任务的结果。</p>
                    </div>
                </div>

                <div class="mb-8">
                    <h3 class="text-xl font-semibold mb-4 flex items-center text-blue-700">
                        <i class="fas fa-code mr-2"></i>
                        示例代码
                    </h3>
                    <div class="code-block p-4 rounded-lg text-gray-200 overflow-x-auto">
                        <pre><code class="language-java">import java.util.concurrent.*;

public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        // 异步任务1
        CompletableFuture&lt;Integer&gt; future1 = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(2000); // 模拟耗时操作
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 42;
        }, executorService);

        // 异步任务2，依赖任务1的结果
        CompletableFuture&lt;String&gt; future2 = future1.thenApplyAsync(result -> {
            return "结果是: " + result;
        }, executorService);

        // 打印最终结果
        System.out.println(future2.get()); // 输出: 结果是: 42

        executorService.shutdown();
    }
}</code></pre>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 flex items-center">
                    <i class="fas fa-star text-yellow-400 mr-3"></i>
                    CompletableFuture的优势
                </h3>
                <div class="grid md:grid-cols-2 gap-4">
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-bold text-blue-800 mb-2">支持回调机制</h4>
                        <p class="text-blue-700">CompletableFuture允许在异步任务完成后执行回调操作，并且支持链式操作，能在一个异步任务完成后立即执行下一个操作。</p>
                    </div>
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-bold text-blue-800 mb-2">不阻塞主线程</h4>
                        <p class="text-blue-700">CompletableFuture的回调方法thenApply()等都不会阻塞主线程，它们会在异步任务完成后立即执行。</p>
                    </div>
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-bold text-blue-800 mb-2">多任务组合</h4>
                        <p class="text-blue-700">CompletableFuture可以组合多个任务，例如使用thenCombine()方法将多个任务的结果合并。</p>
                    </div>
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-bold text-blue-800 mb-2">异常处理</h4>
                        <p class="text-blue-700">CompletableFuture提供了内置的异常处理机制（如exceptionally()），使得异步编程变得更加健壮。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Comparison Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="w-8 h-8 bg-indigo-600 rounded-full flex items-center justify-center text-white mr-4">3</span>
                Future与CompletableFuture的比较
            </h2>
            <div class="bg-white rounded-xl p-8 shadow-lg">
                <p class="mb-8">通过上面的介绍，我们可以总结出<span class="font-bold text-purple-700">Future</span>和<span class="font-bold text-blue-600">CompletableFuture</span>之间的几个关键区别。</p>
                
                <div class="overflow-x-auto">
                    <table class="comparison-table w-full">
                        <thead>
                            <tr>
                                <th class="px-6 py-3 text-left text-sm font-medium">特性</th>
                                <th class="px-6 py-3 text-left text-sm font-medium">Future</th>
                                <th class="px-6 py-3 text-left text-sm font-medium">CompletableFuture</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium">异步任务执行</td>
                                <td class="px-6 py-4">submit()提交任务并通过get()获取结果，阻塞调用</td>
                                <td class="px-6 py-4">提供thenApply(), thenAccept()等无阻塞回调函数</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium">回调机制</td>
                                <td class="px-6 py-4">不支持回调机制</td>
                                <td class="px-6 py-4">支持回调机制，支持链式调用</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium">阻塞行为</td>
                                <td class="px-6 py-4">get()阻塞，等待任务结果</td>
                                <td class="px-6 py-4">不阻塞，任务完成后通过回调方法处理</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium">异常处理</td>
                                <td class="px-6 py-4">需要外部代码进行异常处理</td>
                                <td class="px-6 py-4">提供exceptionally()等方法，内置异常处理机制</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium">多任务组合</td>
                                <td class="px-6 py-4">无法直接组合多个任务</td>
                                <td class="px-6 py-4">支持任务组合（thenCombine(), thenCompose()等）</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap font-medium">任务完成后的操作</td>
                                <td class="px-6 py-4">只能通过get()获取结果，阻塞</td>
                                <td class="px-6 py-4">支持任务完成后自动执行操作，如thenApply()等</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>

        <!-- Use Cases Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="w-8 h-8 bg-green-600 rounded-full flex items-center justify-center text-white mr-4">4</span>
                使用场景
            </h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl p-8 shadow-lg">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center text-purple-700">
                        <i class="fas fa-check-circle mr-3"></i>
                        使用Future的场景
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-3"></i>
                            <span>适合需要获取异步任务结果的场景。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-3"></i>
                            <span>如果你只关心任务的最终结果，而不需要额外的任务组合或回调机制，Future即可满足需求。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-3"></i>
                            <span>示例场景：一个后台任务异步执行后，主线程需要等待任务完成，并获取计算结果。</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white rounded-xl p-8 shadow-lg">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center text-blue-700">
                        <i class="fas fa-bolt mr-3"></i>
                        使用CompletableFuture的场景
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check text-blue-500 mt-1 mr-3"></i>
                            <span>适合需要任务组合和回调机制的复杂异步任务。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-blue-500 mt-1 mr-3"></i>
                            <span>如果需要执行多个异步任务并合并其结果，或者在任务完成后立即执行回调，CompletableFuture是一个更合适的选择。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-blue-500 mt-1 mr-3"></i>
                            <span>示例场景：多个异步任务依赖于前一个任务的结果，或者在任务失败时需要进行重试等操作。</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Exception Handling Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="w-8 h-8 bg-red-600 rounded-full flex items-center justify-center text-white mr-4">5</span>
                异常处理
            </h2>
            <div class="bg-white rounded-xl p-8 shadow-lg">
                <p class="mb-6">异常处理是异步编程中的一个重要方面。在<span class="font-bold text-purple-700">Future</span>中，异常只能通过<span class="font-bold">get()</span>方法抛出并需要显式捕获。而<span class="font-bold text-blue-600">CompletableFuture</span>提供了更灵活的异常处理机制，可以通过<span class="font-bold">exceptionally()</span>、<span class="font-bold">handle()</span>等方法进行处理。</p>
                
                <h3 class="text-2xl font-semibold mt-8 mb-4 flex items-center text-blue-700">
                    <i class="fas fa-bug mr-3"></i>
                    使用CompletableFuture的异常处理
                </h3>
                <div class="code-block p-4 rounded-lg text-gray-200 overflow-x-auto mb-6">
                    <pre><code class="language-java">CompletableFuture.supplyAsync(() -> {
    if (true) throw new RuntimeException("出错了");
    return 42;
}).exceptionally(ex -> {
    System.out.println("发生异常: " + ex.getMessage());
    return -1;
}).thenAccept(result -> {
    System.out.println("结果: " + result);
});</code></pre>
                </div>
                <div class="bg-blue-50 border-l-4 border-blue-400 p-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-info-circle text-blue-400 mt-1 mr-3"></i>
                        </div>
                        <div>
                            <p class="text-blue-700">在上面的例子中，exceptionally()方法处理了任务执行中的异常。如果发生异常，返回默认值-1，然后继续执行后续操作。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="w-8 h-8 bg-teal-600 rounded-full flex items-center justify-center text-white mr-4">6</span>
                概念关系图
            </h2>
            <div class="bg-white rounded-xl p-8 shadow-lg">
                <div class="mermaid">
                    graph TD
                        A[异步编程] --> B(Future)
                        A --> C(CompletableFuture)
                        B --> D[阻塞获取结果]
                        B --> E[不支持回调]
                        C --> F[非阻塞回调]
                        C --> G[链式调用]
                        C --> H[异常处理]
                        C --> I[任务组合]
                        style A fill:#f0f9ff,stroke:#0284c7
                        style B fill:#f5f3ff,stroke:#7c3aed
                        style C fill:#eff6ff,stroke:#2563eb
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="footer text-white py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold">技术小馆</h3>
                    <p class="text-gray-400 mt-1">深入解析技术细节，提升编程技能</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-300">
                        <i class="fas fa-globe mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            mermaid.initialize({
                startOnLoad: true,
                theme: 'default',
                flowchart: {
                    useMaxWidth: true,
                    htmlLabels: true,
                    curve: 'basis'
                }
            });
        });
    </script>
</body>
</html>